var keyword = '';
    function GetQueryString(name) {
      var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
      var r = window.location.search.substr(1).match(reg);
      if (r != null) return decodeURI(r[2]);
      return null;
    }
    // console.log(GetQueryString("id"))
    var id = GetQueryString("id");
    // $(".search-btn").click(() => {
    //   getInput()
    // })

    if(!id){
      location.href="./news.html"
    }

    $(".news-filter-nav-bar").click(function () {
      $(this).siblings().toggle()
    })

    $(document).delegate(".news-filter-item", "click", function () {
      console.log($(this).data("id"))
    })

    // 获取左侧分类的数据
    function getClassData() {
      $.ajax({
        url: `${HOST}/index/article/cate`,
        type: "post",
        success: (res) => {
          if (res.success == 1) {
            var data = res.data,
              str = "";
            for (var i = 0; i < data.length; i++) {
              str += `<a href="./news.html?id=${data[i].id}">
                        <div class="news-filter-item">${data[i].name}</div>
                      </a>`
            }
            $(".news-filter-items-box").html(str);
          }

        }
      })
    }

    $(".news-search-content input").bind('keydown', function (event) {
      var event = window.event || arguments.callee.caller.arguments[0];
      if (event.keyCode == 13) {
        keyword = $(".news-search-content input").val()
        if (keyword == '') {
          alert("请填写搜索词!")
          return;
        }
        $(location).prop("href", './news.html?keyword=' + keyword)
      }
    });

    $(".search-btn").click(function () {
      keyword = $(".news-search-content input").val()
      if (keyword == '') {
        alert("请填写搜索词!")
        return;
      }
      $(location).prop("href", './news.html?keyword=' + keyword)
    })

    /* 
    获取文章内容
    */
    function getArtData(id) {
      $.ajax({
        url: `${HOST}/index/article/articleDetails`,
        type: "post",
        data: {
          id
        },
        success: (res) => {
          // console.log(res)
          if (res.success == 1) {
            var time = timer(res.data.create_time)
            $(".selected-page").html(res.data.title)
            $(".news-details-timer").html(time)
            $(".news-details-title").html(res.data.title)
            $(".news-details-content").html(res.data.content)
          }
        }
      })
    }

    function timer(e) {
      var time = new Date(e * 1000)
      var y = time.getFullYear();
      var mon = time.getMonth() + 1;
      var day = time.getDate();
      var hour = time.getHours() < 10 ? "0" + time.getHours() : time.getHours();
      var min = time.getMinutes() < 10 ? "0" + time.getHours() : time.getHours();
      // var sed = time.getSeconds()<10?"0"+time.getHours():time.getHours();
      return `${y}年${mon}月${day}日 ${hour}:${min}`;

    }
    getClassData()
    getArtData(id)